﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventScavenger
{
    public partial class CollectorEdit : Form
    {
        public CollectorEdit()
        {
            InitializeComponent();
        }

        private Collector selectedCollector = new Collector();
        public Collector SelectedCollector
        {
            get { return selectedCollector; }
            set { selectedCollector = value; }
        }

        #region Form events
        private void CollectorEdit_Load(object sender, EventArgs e)
        {
            txtName.Text = selectedCollector.Name;
            chkRecyclingEnabled.Checked = selectedCollector.ThreadRecyclingEnabled;
            numericUpDownRecycleFreq.Value = selectedCollector.ThreadRecycleFrequencyMinutes;
            dateTimeChooserRecycleTime.SelectedDateTime = selectedCollector.NextRecycleTime;
            chkImportsEnabled.Checked = selectedCollector.ImportsEnabled;
            numericUpDownImportFrequency.Value = selectedCollector.ImportFrequency;
        }
        #endregion

        #region Button events
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Length == 0)
            {
                MessageBox.Show("You must specify a collector name!", "Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                selectedCollector.Name = txtName.Text;
                selectedCollector.ThreadRecyclingEnabled = chkRecyclingEnabled.Checked;
                selectedCollector.ThreadRecycleFrequencyMinutes = Convert.ToInt32(numericUpDownRecycleFreq.Value);
                selectedCollector.NextRecycleTime = dateTimeChooserRecycleTime.SelectedDateTime;
                selectedCollector.ImportsEnabled = chkImportsEnabled.Checked;
                selectedCollector.ImportFrequency = (int)numericUpDownImportFrequency.Value;
                DialogResult = DialogResult.OK;
                Close();
            }
        }
        #endregion

        #region Checkbox events
        private void chkRecyclingEnabled_CheckedChanged(object sender, EventArgs e)
        {
            numericUpDownRecycleFreq.Enabled = chkRecyclingEnabled.Checked;
            dateTimeChooserRecycleTime.Enabled = chkRecyclingEnabled.Checked;
        } 
        private void chkImportsEnabled_CheckedChanged(object sender, EventArgs e)
        {
            numericUpDownImportFrequency.Enabled = chkImportsEnabled.Checked;
        }
        #endregion        


    }
}
